package com.ins.controller;

import com.ins.common.utils.Result;
import com.ins.model.dto.app.AppInfoMarketDTO;
import com.ins.model.entity.AppInfoMarket;
import com.ins.model.query.AppInfoMarketQuery;
import com.ins.model.vo.AppInfoMarketVO;
import com.ins.service.AppInfoMarketService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.dromara.hutool.core.bean.BeanUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 信息集市
 *
 * @author ins
 * @since 2024-05-14
 */
@RestController
@RequestMapping("/info")
public class AppInfoMarketController {

    @Resource
    private AppInfoMarketService appInfoMarketService;

    /**
     * 添加 信息集市
     *
     * @param dto 信息集市
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody @Validated AppInfoMarketDTO dto) {
        AppInfoMarket market = BeanUtil.copyProperties(dto, AppInfoMarket.class);
        return Result.ok(appInfoMarketService.save(market));
    }


    /**
     * 根据主键删除信息集市
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    public Result<Boolean> remove(@PathVariable Serializable id) {
        return Result.ok(appInfoMarketService.removeById(id));
    }


    /**
     * 根据主键更新信息集市
     *
     * @param appInfoMarket 信息集市
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    public Result<Boolean> update(@RequestBody AppInfoMarket appInfoMarket) {
        return Result.ok(appInfoMarketService.updateById(appInfoMarket));
    }


    /**
     * 查询所有信息集市
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    public Result<List<AppInfoMarket>> list() {
        return Result.ok(appInfoMarketService.list());
    }


    /**
     * 根据信息集市主键获取详细信息。
     *
     * @param id appInfoMarket主键
     * @return 信息集市详情
     */
    @GetMapping("/getInfo")
    public Result<AppInfoMarketVO> getInfo(Long id) {
        return Result.ok(appInfoMarketService.getInfo(id));
    }


    /**
     * 分页查询信息集市
     *
     * @param query 查询参数对象
     * @return 分页对象
     */
    @GetMapping("/page")
    public Result<Page<AppInfoMarketVO>> page(AppInfoMarketQuery query) {
        return Result.ok(appInfoMarketService.page(query));
    }

}